package org.springframework.orm.ibatis.support;

import org.springframework.dao.support.DaoSupport;
import org.springframework.orm.ibatis.SqlMapClientTemplate;

import com.ibatis.sqlmap.client.SqlMapClient;

public abstract class PartitionedSqlMapClientDaoSupport extends DaoSupport {
	private SqlMapClientCluster sqlMapClientCluster;
	
	public final void setSqlMapClientCluster(SqlMapClientCluster sqlMapClientCluster) {
		this.sqlMapClientCluster = sqlMapClientCluster;
	}
	
	protected void checkDaoConfig() throws IllegalArgumentException {
		if (sqlMapClientCluster == null) {
			throw new IllegalArgumentException("sqlMapClientCluster is required");
		}
	}

	public final SqlMapClientTemplate getMasterSqlMapClientTemplate() {
		return sqlMapClientCluster.getMasterSqlMapClientTemplate();
	}
	
	public final SqlMapClientTemplate getSlaveSqlMapClientTemplate(int partition) {
		return sqlMapClientCluster.getSlaveSqlMapClientTemplate(partition);
	}
	
	public final SqlMapClient getMasterSqlMapClient() {
		return sqlMapClientCluster.getMasterSqlMapClient();
	}
	
	public final SqlMapClient getSlaveSqlMapClient(int partition) {
		return sqlMapClientCluster.getSlaveSqlMapClient(partition);
	}
	
	public final int getNumberOfSlaveSqlMapClient() {
		return sqlMapClientCluster.getNumberOfSlaveSqlMapClient();
	}
}
